package com.zs.admin.controller.wisdbook;

import com.zs.admin.aop.Log;
import com.zs.admin.service.wisdbook.IWisdbookService;
import com.zs.admin.validate.commons.IdValidate;
import com.zs.admin.validate.wisdbook.WisdbookCreateValidate;
import com.zs.admin.validate.wisdbook.WisdbookUpdateValidate;
import com.zs.admin.validate.wisdbook.WisdbookSearchValidate;
import com.zs.admin.validate.commons.PageValidate;
import com.zs.admin.vo.wisdbook.WisdbookListedVo;
import com.zs.admin.vo.wisdbook.WisdbookDetailVo;
import com.zs.common.core.AjaxResult;
import com.zs.common.core.PageResult;
import com.zs.common.validator.annotation.IDMust;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("api/wisdbook")
@Api(tags = "智书管理")
public class WisdbookController {

    @Resource
    IWisdbookService iWisdbookService;

    @GetMapping("/list")
    @ApiOperation(value="智书列表")
    public AjaxResult<PageResult<WisdbookListedVo>> list(@Validated PageValidate pageValidate,
                                                     @Validated WisdbookSearchValidate searchValidate) {
        PageResult<WisdbookListedVo> list = iWisdbookService.list(pageValidate, searchValidate);
        return AjaxResult.success(list);
    }

    @GetMapping("/detail")
    @ApiOperation(value="智书详情")
    public AjaxResult<WisdbookDetailVo> detail(@Validated @IDMust() @RequestParam("id") Integer id) {
        WisdbookDetailVo detail = iWisdbookService.detail(id);
        return AjaxResult.success(detail);
    }

    @Log(title = "智书新增")
    @PostMapping("/add")
    @ApiOperation(value="智书新增")
    public AjaxResult<Object> add(@Validated @RequestBody WisdbookCreateValidate createValidate) {
        iWisdbookService.add(createValidate);
        return AjaxResult.success();
    }

    @Log(title = "智书编辑")
    @PostMapping("/edit")
    @ApiOperation(value="智书编辑")
    public AjaxResult<Object> edit(@Validated @RequestBody WisdbookUpdateValidate updateValidate) {
        iWisdbookService.edit(updateValidate);
        return AjaxResult.success();
    }

    @Log(title = "智书删除")
    @PostMapping("/del")
    @ApiOperation(value="智书删除")
    public AjaxResult<Object> del(@Validated @RequestBody IdValidate idValidate) {
        iWisdbookService.del(idValidate.getId());
        return AjaxResult.success();
    }

}
